package com.cxhome.cxinfox.cxmenu;

import com.jfinal.plugin.activerecord.Page;
import com.traffic.managent.annotation.ControllerBind;
import com.traffic.managent.base.CxBaseController;
import com.traffic.managent.model.system.Operator;
import com.traffic.managent.util.UtilsUtils;

/**
 * 菜单
 * 
 */
@ControllerBind(controllerKey = "/system/cxoperator")
public class OperatorController extends CxBaseController {

	private static final String path = "/pages/system/cxoperator/cxoperator_";
	OperatorService operatorService = new OperatorService();

	public void index() {
		list();
	}

	public void list() {

		Operator model = getModelByAttr(Operator.class);
		Page<Operator> page = OperatorService.service.paginate(model, getPaginator());

		setAttr("page", page);
		setAttr("attr", model);
		render(path + "list.html");
	}

	/**
	 * 跳转新增页面
	 */
	public void add() {
		setAttr("selectMoudle", operatorService.selectMoudle(""));
		render(path + "add.html");
	}

	/**
	 * 查看详情
	 */
	public void view() {
		Operator model = Operator.dao.findById(getPara());
		setAttr("model", model);
		render(path + "view.html");
	}

	public void delete() {
		Operator.dao.deleteById(getPara());
		list();
	}

	/**
	 * 跳转编辑页面
	 */
	public void edit() {
		Operator model = Operator.dao.findById(getPara());

		setAttr("selectMoudle", operatorService.selectMoudle(model.getStr("moduleids")));
		setAttr("model", model);
		render(path + "edit.html");
	}

	/**
	 * 保存
	 */
	public void save() {
		String pid = getPara();
		Operator model = getModel(Operator.class);
		// 日志添加
		if (pid != null && !"".equals(pid)) { // 更新
			model.update();
		} else { // 新增
			model.remove("id");
			model.put("ids", UtilsUtils.getRandomId(30));
			model.save();
		}
		renderMessage("保存成功");
	}

}
